//
//  EditeMyShopViewController.m
//  ShangPiBao
//
//  Created by chirui on 2017/10/25.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "EditeMyShopViewController.h"
#import "RangeEditViewController.h"
#import "ContactWayViewController.h"

@interface EditeMyShopViewController ()
{

    NSString * classIdStr;
    NSString * rangeStr; // 经营范围
    NSString * InformationStr; //联系方式
}
@property (weak, nonatomic) IBOutlet UITextField *companyText;
@property (weak, nonatomic) IBOutlet UIButton *keepBtn;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *classLabel;


@end

@implementation EditeMyShopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    TitleView(@"编辑");
    
    _companyText.text = self.dataDic[@"ucn"];
    _addressLabel.text = self.dataDic[@"ucarea"];
    InformationStr = self.dataDic[@"uci"];
    classIdStr = self.dataDic[@"ucid"];
    rangeStr = self.dataDic[@"uor"];
    
    [CLASS_ID_ARRAY enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj isEqualToString:self.dataDic[@"ucid"]]) {
            NSLog(@"%@-索引%d 对应id = %@",obj, (int)idx,CLASS_ID_ARRAY[idx]);
            _classLabel.text =  CLASS_ARRAY[idx];
        }
    }];
    
    _keepBtn.layer.cornerRadius = 45/2.f;
    _keepBtn.layer.masksToBounds = YES;
    
//    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_nav_return" target:self action:@selector(back)];
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)addressChoose:(id)sender {
    
    NSArray * bankArray = @[@"北京市",@"天津市",@"河北省",@"山西省",@"内蒙古区",@"辽宁省",@"吉林省",@"黑龙江省",@"上海市",@"江苏省",@"浙江省",@"安徽省",@"福建省",@"江西省",@"山东省",@"河南省",@"湖北省",@"湖南省",@"广东省",@"广西区",@"海南省",@"重庆市",@"四川省",@"贵州省",@"云南省",@"西藏区",@"陕西省",@"甘肃省",@"青海省",@"宁夏区",@"新疆区",@"台湾省",@"香港特区",@"澳门特区"];
    zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:bankArray andHeadTitle:@"省份" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
        _addressLabel.textColor =[UIColor blackColor];
        _addressLabel.text = choiceString;
        [pickerView dismissPicker];
    }];
    [pickerView show];
    
}

- (IBAction)classChoose:(id)sender {
    
    zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:CLASS_ARRAY andHeadTitle:@"行业类型" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
        _classLabel.textColor =[UIColor blackColor];
        _classLabel.text = choiceString;
        
        [CLASS_ARRAY enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            if ([obj isEqualToString:choiceString]) {
                NSLog(@"%@-索引%d 对应id = %@",obj, (int)idx,CLASS_ID_ARRAY[idx]);
                classIdStr =  CLASS_ID_ARRAY[idx];
            }
        }];
        
        
        [pickerView dismissPicker];
    }];
    [pickerView show];
    
}

- (IBAction)rangeClick:(id)sender {
    
    RangeEditViewController * range =[[RangeEditViewController alloc]init];
    range.messageStr = self.dataDic[@"uor"];
    range.rangeBlock= ^(NSString * Str){
        
        rangeStr = Str;
    };
    [self.navigationController pushViewController:range animated:YES];
    
}
- (IBAction)typeClick:(id)sender {
    
    ContactWayViewController * contact =[[ContactWayViewController alloc]init];
    contact.dataStr = self.dataDic[@"uci"];
    contact.infoBlock= ^(NSString * str){
        InformationStr = str;
    };
    [self.navigationController pushViewController:contact animated:YES];
}

- (IBAction)keepBtnClick:(id)sender {
    
    [self upDataCompanyMessageForRequest];
}

-(void)upDataCompanyMessageForRequest{
    
    
    NSString * md5ver = [SHJudgeTools md532BitLower:[NSString
                                                     stringWithFormat:@"%@api.shangpibao.com",USER_DEFAULTGet(@"phone")]];
    
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",address_url,upData_companyMessage_api];
    NSDictionary * dic = @{@"uphone":USER_DEFAULTGet(@"phone"),
                           @"ucn":_companyText.text,
                           @"ucid":classIdStr,
                           @"ucarea":_addressLabel.text,
                           @"uci":InformationStr,
                           @"uor":rangeStr,
                           @"ver":md5ver};
    
    NSLog(@"parametersStr = %@",parametersStr);
        SHuiMBhubNoTimeLoding;
    [PostNetWorking postNetWorkingStr:parametersStr andparameters:dic   Success:^(id responseObject) {
        SHuiMBHidleYes;
        if ([responseObject[@"err"] intValue]==0) {
            
            SHuiMBhudTextTimeStr(@"保存成功");
            
        } else {
            
            SHuiMBhudTextTimeStr(EorrMessageStr);
        }
        
    } failed:^(NSError *error) {
        
        SHuiMBHidleYes;
        SHuiMBhudTextTimeStr(@"请检查您的网络!");
    }];
    
}


@end
